package com.funcpro.service.impl;

import com.funcpro.common.Response.BaseResponse;
import com.funcpro.common.utils.AesUtils;
import com.funcpro.dao.mapper.UserMapper;
import com.funcpro.model.entity.UsersEntity;
import com.funcpro.model.vo.LoginUser;
import com.funcpro.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Duration;

/**
 * @author ZYT
 * @desc
 * @time 2023-11-08 11:36
 */
@Service
public class UserServiceImpl  implements UserService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private RedisTemplate redisTemplate;
    private static String redisKey="test";

    @Override
    public BaseResponse login(LoginUser loginUser) {
        UsersEntity usersEntity=new UsersEntity();
        usersEntity.setPhoneNo(AesUtils.encryptHex(loginUser.getPhoneNo()));
        usersEntity.setUserName(loginUser.getUserName());
        usersEntity.setUserId(11);
        userMapper.insert(usersEntity);
        //userMapper.insertInto(usersEntity);
        return BaseResponse.ok();
    }

    @Override
    public Page<LoginUser> query(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        Page<LoginUser> resultList= userMapper.query();
     /*   for (LoginUser loginUser : resultList) {
            redisTemplate.opsForValue().set(redisKey,loginUser.getUserName(), Duration.ofHours(1));
        }*/
        return resultList;
    }
}
